package me.ivps.android.weibo.ui.main;

import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import me.ivps.android.weibo.R;
import me.ivps.android.weibo.bean.AccountBean;
import me.ivps.android.weibo.bean.CommentListBean;
import me.ivps.android.weibo.bean.MessageListBean;
import me.ivps.android.weibo.bean.UnreadBean;
import me.ivps.android.weibo.bean.UserBean;
import me.ivps.android.weibo.othercomponent.ClearCacheTask;
import me.ivps.android.weibo.othercomponent.ConnectionChangeReceiver;
import me.ivps.android.weibo.othercomponent.MusicReceiver;
import me.ivps.android.weibo.support.database.AccountDBTask;
import me.ivps.android.weibo.support.database.DatabaseManager;
import me.ivps.android.weibo.support.lib.LongClickableLinkMovementMethod;
import me.ivps.android.weibo.support.lib.RecordOperationAppBroadcastReceiver;
import me.ivps.android.weibo.support.settinghelper.SettingUtility;
import me.ivps.android.weibo.support.utils.AppEventAction;
import me.ivps.android.weibo.support.utils.BundleArgsConstants;
import me.ivps.android.weibo.support.utils.GlobalContext;
import me.ivps.android.weibo.support.utils.Utility;
import me.ivps.android.weibo.ui.dm.DMUserListFragment;
import me.ivps.android.weibo.ui.maintimeline.FriendsTimeLineFragment;
import me.ivps.android.weibo.ui.search.SearchMainParentFragment;
import me.ivps.android.weibo.ui.send.WriteWeiboActivity;
import me.ivps.android.weibo.ui.userinfo.MyFavListFragment;
import me.ivps.android.weibo.ui.userinfo.UserInfoActivity;
import me.ivps.android.weibo.ui.userinfo.UserInfoFragment;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.espian.showcaseview.ShowcaseView;
import com.espian.showcaseview.targets.ViewTarget;
import com.slidingmenu.lib.SlidingMenu;

/**
 * 微博主列表界面
 * 
 * User: Jiang Qi Date: 12-7-27
 */
public class MainTimeLineActivity extends MainTimeLineParentActivity {
    
    /**
     * 快速滚动监听器
     * 
     * @author Zoe
     * 
     */
    public static interface ScrollableListFragment {
        /**
         * 快速滚动列表到顶部
         */
        public void scrollToTop();
    }
    
    public static final int REQUEST_CODE_UPDATE_FRIENDS_TIMELINE_COMMENT_REPOST_COUNT = 0;
    
    public static final int REQUEST_CODE_UPDATE_MENTIONS_WEIBO_TIMELINE_COMMENT_REPOST_COUNT = 1;
    
    public static final int REQUEST_CODE_UPDATE_MY_FAV_TIMELINE_COMMENT_REPOST_COUNT = 2;
    
    /**
     * 当前账户信息
     */
    private AccountBean accountBean;
    
    private NewMsgInterruptBroadcastReceiver newMsgInterruptBroadcastReceiver;
    
    private MusicReceiver musicReceiver;
    
    /**
     * 滚动监听器
     */
    private ScrollableListFragment currentFragment;
    
    private TextView titleText;
    
    private View clickToTop;
    
    /**
     * 生成 Intent
     * 
     * @return
     */
    public static Intent newIntent() {
        return new Intent(GlobalContext.getInstance(),
                MainTimeLineActivity.class);
    }
    
    /**
     * 启动此界面, 并设置 AccountBean 对象(在该界面 Activity 中提供 newIntent 方法, 来设置 Bundle 对象)
     * 
     * @param accountBean
     * @return
     */
    public static Intent newIntent(AccountBean accountBean) {
        Intent intent = newIntent();
        intent.putExtra(BundleArgsConstants.ACCOUNT_EXTRA, accountBean);
        return intent;
    }
    
    /**
     * 返回用于通知栏的 Intent
     * 
     * notification bar
     */
    public static Intent newIntent(AccountBean accountBean,
            MessageListBean mentionsWeiboData,
            CommentListBean mentionsCommentData,
            CommentListBean commentsToMeData, UnreadBean unreadBean) {
        Intent intent = newIntent();
        intent.putExtra(BundleArgsConstants.ACCOUNT_EXTRA, accountBean);
        intent.putExtra(BundleArgsConstants.MENTIONS_WEIBO_EXTRA,
                mentionsWeiboData);
        intent.putExtra(BundleArgsConstants.MENTIONS_COMMENT_EXTRA,
                mentionsCommentData);
        intent.putExtra(BundleArgsConstants.COMMENTS_TO_ME_EXTRA,
                commentsToMeData);
        intent.putExtra(BundleArgsConstants.UNREAD_EXTRA, unreadBean);
        return intent;
    }
    
    /**
     * 返回 Access_token
     * 
     * @return
     */
    public String getToken() {
        return accountBean.getAccess_token();
    }
    
    /**
     * 设置标题
     * 
     * @param title
     */
    public void setTitle(String title) {
        if (TextUtils.isEmpty(title)) {
            titleText.setVisibility(View.GONE);
        }
        else {
            titleText.setText(title);
            titleText.setVisibility(View.VISIBLE);
        }
    }
    
    /**
     * 设置标题
     */
    @Override
    public void setTitle(int res) {
        setTitle(getString(res));
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        // 保存当前 Account 信息
        outState.putParcelable("account", accountBean);
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        if (savedInstanceState != null) {
            accountBean = savedInstanceState.getParcelable("account");
        }
        else {
            Intent intent = getIntent();
            accountBean = intent
                    .getParcelableExtra(BundleArgsConstants.ACCOUNT_EXTRA);
        }
        
        if (accountBean == null) {
            accountBean = GlobalContext.getInstance().getAccountBean();
        }
        
        GlobalContext.getInstance().setGroup(null);
        GlobalContext.getInstance().setAccountBean(accountBean);
        
        SettingUtility.setDefaultAccountId(accountBean.getUid());
        
        buildInterface(savedInstanceState);
        
        // 延迟执行清扫任务
        Executors.newSingleThreadScheduledExecutor().schedule(
                new ClearCacheTask(), 8, TimeUnit.SECONDS);
    }
    
    private void buildInterface(Bundle savedInstanceState) {
        // 设置为当前登录账户名
        getActionBar().setTitle(
                GlobalContext.getInstance().getCurrentAccountName());
        
        // 清空默认背景
        getWindow().setBackgroundDrawable(null);
        
        setContentView(R.layout.menu_right);
        
        // 菜单, 即, 是否包含左侧菜单, 即是否显示两屏页面
        boolean isPhone = (findViewById(R.id.menu_frame) == null);
        if (isPhone) {
            buildPhoneInterface(savedInstanceState);
        }
        else {
            buildPadInterface(savedInstanceState);
        }
        
        // 构建自定义 ActionBar
        buildCustomActionBarTitle(savedInstanceState);
        
        if (savedInstanceState == null) {
            initFragments();
            FragmentTransaction secondFragmentTransaction = getSupportFragmentManager()
                    .beginTransaction();
            secondFragmentTransaction.replace(R.id.menu_frame,
                    getMenuFragment(), LeftMenuFragment.class.getName());
            getSlidingMenu().showContent();
            secondFragmentTransaction.commit();
        }
        configSlidingMenu(isPhone);
    }
    
    private void initFragments() {
        Fragment friend = getFriendsTimeLineFragment();
        Fragment mentions = getMentionsTimeLineFragment();
        Fragment comments = getCommentsTimeLineFragment();
        
        Fragment fav = getFavFragment();
        Fragment myself = getMyProfileFragment();
        
        FragmentTransaction fragmentTransaction = getSupportFragmentManager()
                .beginTransaction();
        if (!friend.isAdded()) {
            fragmentTransaction.add(R.id.menu_right_fl, friend,
                    FriendsTimeLineFragment.class.getName());
            fragmentTransaction.hide(friend);
        }
        if (!mentions.isAdded()) {
            fragmentTransaction.add(R.id.menu_right_fl, mentions,
                    MentionsTimeLine.class.getName());
            fragmentTransaction.hide(mentions);
            
        }
        if (!comments.isAdded()) {
            fragmentTransaction.add(R.id.menu_right_fl, comments,
                    CommentsTimeLine.class.getName());
            fragmentTransaction.hide(comments);
            
        }
        
        if (!fav.isAdded()) {
            fragmentTransaction.add(R.id.menu_right_fl, fav,
                    MyFavListFragment.class.getName());
            fragmentTransaction.hide(fav);
        }
        
        if (!myself.isAdded()) {
            fragmentTransaction.add(R.id.menu_right_fl, myself,
                    UserInfoFragment.class.getName());
            fragmentTransaction.hide(myself);
        }
        
        if (GlobalContext.getInstance().getAccountBean().isBlack_magic()) {
            Fragment search = getSearchFragment();
            Fragment dm = getDMFragment();
            
            if (!search.isAdded()) {
                fragmentTransaction.add(R.id.menu_right_fl, search,
                        SearchMainParentFragment.class.getName());
                fragmentTransaction.hide(search);
                
            }
            
            if (!dm.isAdded()) {
                fragmentTransaction.add(R.id.menu_right_fl, dm,
                        DMUserListFragment.class.getName());
                fragmentTransaction.hide(dm);
                
            }
        }
        
        if (!fragmentTransaction.isEmpty()) {
            fragmentTransaction.commit();
            getSupportFragmentManager().executePendingTransactions();
        }
    }
    
    private void configSlidingMenu(boolean phone) {
        SlidingMenu slidingMenu = getSlidingMenu();
        slidingMenu.setShadowWidthRes(R.dimen.shadow_width);
        slidingMenu.setShadowDrawable(R.drawable.shadow_slidingmenu);
        if (phone) {
            slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        }
        else {
            slidingMenu.setBehindOffset(Utility.getScreenWidth());
        }
        
        slidingMenu.setFadeDegree(0.35f);
        slidingMenu
                .setOnPageScrollListener(new SlidingMenu.OnPageScrollListener() {
                    @Override
                    public void onPageScroll() {
                        LongClickableLinkMovementMethod.getInstance()
                                .setLongClickable(false);
                        (getFriendsTimeLineFragment()).clearActionMode();
                        (getFavFragment()).clearActionMode();
                        (getCommentsTimeLineFragment()).clearActionMode();
                        (getMentionsTimeLineFragment()).clearActionMode();
                        (getMyProfileFragment()).clearActionMode();
                        
                        if (GlobalContext.getInstance().getAccountBean()
                                .isBlack_magic()) {
                            (getSearchFragment()).clearActionMode();
                            (getDMFragment()).clearActionMode();
                        }
                    }
                });
        
        slidingMenu.setOnClosedListener(new SlidingMenu.OnClosedListener() {
            @Override
            public void onClosed() {
                LongClickableLinkMovementMethod.getInstance().setLongClickable(
                        true);
                LocalBroadcastManager
                        .getInstance(MainTimeLineActivity.this)
                        .sendBroadcast(
                                new Intent(
                                        AppEventAction.SLIDING_MENU_CLOSED_BROADCAST));
            }
        });
    }
    
    /**
     * 构造自定义标题栏
     * 
     * @param savedInstanceState
     */
    private void buildCustomActionBarTitle(Bundle savedInstanceState) {
        View title = getLayoutInflater().inflate(
                R.layout.maintimelineactivity_title_layout, null);
        // 标题
        titleText = (TextView) title.findViewById(R.id.tv_title);
        // 快速向上
        clickToTop = title.findViewById(R.id.tv_click_to_top);
        clickToTop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                scrollCurrentListViewToTop();
            }
        });
        // 写微博
        View write = title.findViewById(R.id.btn_write);
        write.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = WriteWeiboActivity.newIntent(GlobalContext
                        .getInstance().getAccountBean());
                startActivity(intent);
            }
        });
        ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT, Gravity.RIGHT);
        getActionBar().setCustomView(title, layoutParams);
        getActionBar().setDisplayShowCustomEnabled(true);
    }
    
    /**
     * 构造手机单屏及侧拉菜单页面
     * 
     * @param savedInstanceState
     */
    private void buildPhoneInterface(Bundle savedInstanceState) {
        // 设置侧拉菜单
        setBehindContentView(R.layout.menu_frame);
        // 启用侧拉菜单
        getSlidingMenu().setSlidingEnabled(true);
        // 全屏允许侧拉
        getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        // 允许 Home Icon 向上返回
        getActionBar().setDisplayHomeAsUpEnabled(true);
        // 左侧菜单
        getSlidingMenu().setMode(SlidingMenu.LEFT);
        // 只允许左侧显示菜单
        getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
    }
    
    /**
     * 构造 Pad 多屏(无侧拉菜单)页面
     * 
     * @param savedInstanceState
     */
    private void buildPadInterface(Bundle savedInstanceState) {
        View v = new View(this);
        setBehindContentView(v);
        // 禁用侧拉菜单
        getSlidingMenu().setSlidingEnabled(false);
        // 不允许侧拉
        getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
    }
    
    /**
     * 快速向上滚动
     */
    private void scrollCurrentListViewToTop() {
        if (this.currentFragment != null) {
            this.currentFragment.scrollToTop();
        }
    }
    
    public View getClickToTopView() {
        return clickToTop;
    }
    
    public void setCurrentFragment(ScrollableListFragment fragment) {
        this.currentFragment = fragment;
    }
    
    @Override
    protected void onResumeFragments() {
        super.onResumeFragments();
        // 插入快速提示
        if (SettingUtility.isClickToTopTipFirstShow()) {
            ViewTarget target = new ViewTarget(getClickToTopView());
            ShowcaseView.insertShowcaseView(target, this, R.string.tip,
                    R.string.click_to_top_tip);
        }
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 关闭数据库
        DatabaseManager.close();
    }
    
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        AccountBean intentAccountBean = intent
                .getParcelableExtra(BundleArgsConstants.ACCOUNT_EXTRA);
        if (intentAccountBean == null) {
            return;
        }
        
        if (accountBean.equals(intentAccountBean)) {
            accountBean = intentAccountBean;
            GlobalContext.getInstance().setAccountBean(accountBean);
            setIntent(intent);
        }
        else {
            finish();
            overridePendingTransition(0, 0);
            startActivity(intent);
            overridePendingTransition(0, 0);
        }
        
    }
    
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        // 清除缓存
        GlobalContext.getInstance().getBitmapCache().evictAll();
        // 结束应用
        finish();
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                // 显示菜单
                getSlidingMenu().showMenu();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
    
    public UserBean getUser() {
        return accountBean.getInfo();
    }
    
    public AccountBean getAccount() {
        return accountBean;
    }
    
    /**
     * 读取剪贴板, 并显示???
     */
    private void readClipboard() {
        ClipboardManager cm = (ClipboardManager) getApplicationContext()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData cmContent = cm.getPrimaryClip();
        if (cmContent == null) {
            return;
        }
        ClipData.Item item = cmContent.getItemAt(0);
        if (item != null) {
            String url = item.coerceToText(this).toString();
            boolean a = !TextUtils.isEmpty(url)
                    && !url.equals(SettingUtility
                            .getLastFoundWeiboAccountLink());
            boolean b = Utility.isWeiboAccountIdLink(url)
                    || Utility.isWeiboAccountDomainLink(url);
            if (a && b) {
                OpenWeiboAccountLinkDialog dialog = new OpenWeiboAccountLinkDialog(
                        url);
                dialog.show(getSupportFragmentManager(), "");
                SettingUtility.setLastFoundWeiboAccountLink(url);
            }
        }
    }
    
    public static class OpenWeiboAccountLinkDialog extends DialogFragment {
        
        private String url;
        
        public OpenWeiboAccountLinkDialog() {
            
        }
        
        public OpenWeiboAccountLinkDialog(String url) {
            this.url = url;
        }
        
        @Override
        public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
            outState.putString("url", url);
        }
        
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            if (savedInstanceState != null) {
                this.url = savedInstanceState.getString("url");
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(R.string.find_weibo_account_link)
                    .setMessage(url)
                    .setPositiveButton(R.string.open,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    if (Utility.isWeiboAccountIdLink(url)) {
                                        Intent intent = new Intent(
                                                getActivity(),
                                                UserInfoActivity.class);
                                        intent.putExtra("id", Utility
                                                .getIdFromWeiboAccountLink(url));
                                        startActivity(intent);
                                    }
                                    else if (Utility
                                            .isWeiboAccountDomainLink(url)) {
                                        Intent intent = new Intent(
                                                getActivity(),
                                                UserInfoActivity.class);
                                        intent.putExtra(
                                                "domain",
                                                Utility.getDomainFromWeiboAccountLink(url));
                                        startActivity(intent);
                                    }
                                }
                            })
                    .setNegativeButton(R.string.cancel,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    
                                }
                            });
            return builder.create();
        }
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        
        // 广播 IntentFilter
        IntentFilter filter = new IntentFilter(
                AppEventAction.NEW_MSG_PRIORITY_BROADCAST);
        filter.setPriority(1);
        
        // 新消息拦截广播接收器
        newMsgInterruptBroadcastReceiver = new NewMsgInterruptBroadcastReceiver();
        Utility.registerReceiverIgnoredReceiverHasRegisteredHereException(this,
                newMsgInterruptBroadcastReceiver, filter);
        
        musicReceiver = new MusicReceiver();
        Utility.registerReceiverIgnoredReceiverHasRegisteredHereException(this,
                musicReceiver,
                AppEventAction.getSystemMusicBroadcastFilterAction());
        
        // 读取剪贴板
        readClipboard();
        
        // ensure timeline picture type is correct
        ConnectionChangeReceiver.judgeNetworkStatus(this);
    }
    
    @Override
    protected void onPause() {
        super.onPause();
        Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(this,
                newMsgInterruptBroadcastReceiver);
        Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(this,
                musicReceiver);
        
        if (isFinishing()) {
            saveNavigationPositionToDB();
        }
    }
    
    /**
     * 保存导航位置到数据库
     */
    public void saveNavigationPositionToDB() {
        int navPosition = getMenuFragment().getCurrentIndex() * 10;
        ActionBar actionBar = getActionBar();
        int second = 0;
        if (actionBar.getNavigationMode() != ActionBar.NAVIGATION_MODE_STANDARD) {
            second = actionBar.getSelectedNavigationIndex();
        }
        int result = navPosition + second;
        GlobalContext.getInstance().getAccountBean()
                .setNavigationPosition(result);
        AccountDBTask.updateNavigationPosition(GlobalContext.getInstance()
                .getAccountBean(), result);
    }
    
    public LeftMenuFragment getMenuFragment() {
        LeftMenuFragment fragment = ((LeftMenuFragment) getSupportFragmentManager()
                .findFragmentByTag(LeftMenuFragment.class.getName()));
        if (fragment == null) {
            fragment = LeftMenuFragment.newInstance();
        }
        return fragment;
    }
    
    public FriendsTimeLineFragment getFriendsTimeLineFragment() {
        FriendsTimeLineFragment fragment = ((FriendsTimeLineFragment) getSupportFragmentManager()
                .findFragmentByTag(FriendsTimeLineFragment.class.getName()));
        if (fragment == null) {
            fragment = FriendsTimeLineFragment.newInstance(getAccount(),
                    getUser(), getToken());
        }
        return fragment;
    }
    
    public MentionsTimeLine getMentionsTimeLineFragment() {
        MentionsTimeLine fragment = ((MentionsTimeLine) getSupportFragmentManager()
                .findFragmentByTag(MentionsTimeLine.class.getName()));
        if (fragment == null) {
            fragment = MentionsTimeLine.newInstance();
        }
        return fragment;
    }
    
    public CommentsTimeLine getCommentsTimeLineFragment() {
        CommentsTimeLine fragment = ((CommentsTimeLine) getSupportFragmentManager()
                .findFragmentByTag(CommentsTimeLine.class.getName()));
        if (fragment == null) {
            fragment = CommentsTimeLine.newInstance();
        }
        return fragment;
    }
    
    public SearchMainParentFragment getSearchFragment() {
        SearchMainParentFragment fragment = ((SearchMainParentFragment) getSupportFragmentManager()
                .findFragmentByTag(SearchMainParentFragment.class.getName()));
        if (fragment == null) {
            fragment = SearchMainParentFragment.newInstance();
        }
        return fragment;
    }
    
    public DMUserListFragment getDMFragment() {
        DMUserListFragment fragment = ((DMUserListFragment) getSupportFragmentManager()
                .findFragmentByTag(DMUserListFragment.class.getName()));
        if (fragment == null) {
            fragment = DMUserListFragment.newInstance();
        }
        return fragment;
    }
    
    public MyFavListFragment getFavFragment() {
        MyFavListFragment fragment = ((MyFavListFragment) getSupportFragmentManager()
                .findFragmentByTag(MyFavListFragment.class.getName()));
        if (fragment == null) {
            fragment = MyFavListFragment.newInstance();
        }
        return fragment;
    }
    
    public UserInfoFragment getMyProfileFragment() {
        UserInfoFragment fragment = ((UserInfoFragment) getSupportFragmentManager()
                .findFragmentByTag(UserInfoFragment.class.getName()));
        if (fragment == null) {
            fragment = UserInfoFragment.newInstance(GlobalContext.getInstance()
                    .getAccountBean().getInfo(), GlobalContext.getInstance()
                    .getSpecialToken());
        }
        return fragment;
    }
    
    /**
     * 新消息拦截广播接收器
     * 
     * @author Zoe
     * 
     */
    private class NewMsgInterruptBroadcastReceiver extends
            RecordOperationAppBroadcastReceiver {
        
        @Override
        public void onReceive(Context context, Intent intent) {
            AccountBean intentAccount = intent
                    .getParcelableExtra(BundleArgsConstants.ACCOUNT_EXTRA);
            // 当前登录账户
            if (accountBean.equals(intentAccount)) {
                // 消息列表
                MessageListBean mentionsWeibo = intent
                        .getParcelableExtra(BundleArgsConstants.MENTIONS_WEIBO_EXTRA);
                // 评论列表
                CommentListBean mentionsComment = intent
                        .getParcelableExtra(BundleArgsConstants.MENTIONS_COMMENT_EXTRA);
                CommentListBean commentsToMe = intent
                        .getParcelableExtra(BundleArgsConstants.COMMENTS_TO_ME_EXTRA);
                
                // 未读数量
                int unreadCount = (mentionsWeibo != null ? mentionsWeibo
                        .getSize() : 0)
                        + (mentionsComment != null ? mentionsComment.getSize()
                                : 0)
                        + (commentsToMe != null ? commentsToMe.getSize() : 0);
                String tip = context.getString(
                        R.string.you_have_new_unread_count,
                        String.valueOf(unreadCount));
                // 显示提示
                Toast.makeText(MainTimeLineActivity.this, tip,
                        Toast.LENGTH_LONG).show();
                // 放弃广播
                abortBroadcast();
            }
        }
    }
    
    /**
     * 设置@ 微博数量
     * 
     * @param count
     */
    public void setMentionsWeiboCount(int count) {
        LeftMenuFragment fragment = getMenuFragment();
        fragment.setMentionWeiboUnreadCount(count);
    }
    
    /**
     * 设置@ 评论数量
     * 
     * @param count
     */
    public void setMentionsCommentCount(int count) {
        LeftMenuFragment fragment = getMenuFragment();
        fragment.setMentionCommentUnreadCount(count);
    }
    
    /**
     * 设置我的评论数量
     * 
     * @param count
     */
    public void setCommentsToMeCount(int count) {
        LeftMenuFragment fragment = getMenuFragment();
        fragment.setCommentUnreadCount(count);
    }
}